﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;

namespace NLBS.Web.UI
{
   public class MessageBox:System.Web.UI.Control
    {
       public MessageBox()
       {
           _msgType = MessageType.Success;
       }

       public MessageBox(MessageType msgType, string title, string content,string bottomContent)
       {
           this.msgType = msgType;
           this.Title = title;
           this.Content = content;
           this.BottomContent = bottomContent;
       }

       public MessageBox(MessageType msgType, string title, string content, string bottomContent, string bottomContentURL,bool reflash)
       {
           this.msgType = msgType;
           this.Title = title;
           this.Content = content;
           this.BottomContent = bottomContent;
           this.BottomContentUrl = bottomContentURL;
           this.EnableRefresh = reflash;
       }


       private MessageType _msgType;
       public MessageType msgType
       {
           get
           {
               return _msgType;
           }
           set
           {
               _msgType = value;
           }
       }

       public string CssStart
       {
           get
           {
               if (_msgType == MessageType.Success)
               {
                   return "messagebox";
               }
               return "errorbox";

           }
       }

       private string _title;
       public string Title
       {
           get { return _title; }
           set { _title = value; }
       }

       private string _content;
       public string Content
       {
           get { return _content; }
           set { _content = value; }
       }

       private string _bottomContent;
       public string BottomContent
       {
           get { return _bottomContent; }
           set { _bottomContent = value; }
       }
       

       private bool _enableRefresh;
       public bool EnableRefresh
       {
           get { return _enableRefresh; }
           set { _enableRefresh = value; }
       }

       private string _bottomContentUrl;
       public string BottomContentUrl
       {
           get { return _bottomContentUrl; }
           set { _bottomContentUrl = value; }
       } 

       protected override void Render(HtmlTextWriter writer)
       {
           StringBuilder sb=new StringBuilder();
           sb.Append("<center>");
           sb.AppendFormat("<div class=\"{0}\">",CssStart);
           sb.AppendFormat("<div class=\"{0}\">{1}</div>",CssStart+"-title",Title);
           sb.AppendFormat("<div class=\"{0}\">{1}</div>",CssStart+"-content",Content);
           sb.AppendFormat("<div id=\"boxBottom\" class=\"{0}\"><a href=\"{2}\">{1}</a></div>", CssStart + "-bottom", BottomContent,BottomContentUrl);
           if (EnableRefresh)
           {
               sb.AppendFormat("<meta http-equiv=\"refresh\" content=\"3;url={0}\" />", BottomContentUrl);
           }
           sb.Append("</div></center>");
           writer.Write(sb.ToString());
           base.Render(writer);
       }
    
    }

   public enum MessageType
   {
       Success,
       Error
   }
}
